#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int GetUglyNumber_Solution(int index) {
	if (index < 7) return index;
	int i2(0), i3(0), i5(0);
	vector<int> ugly(index);
	ugly[0] = 1;
	for (int i = 1; i < index; ++i)
	{
		ugly[i] = min(ugly[i2] * 2, min(ugly[i3] * 3, ugly[i5] * 5));
		if (ugly[i] == ugly[i2] * 2) ++i2;
		if (ugly[i] == ugly[i3] * 3) ++i3;
		if (ugly[i] == ugly[i5] * 5) ++i5;
	}

	return ugly[index - 1];
}

//int main()
//{
//	cout << GetUglyNumber_Solution(7);
//
//	system("pause");
//	return 0;
//}